package com.example.mapper;

import com.example.pojo.Conversations;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ConversationsMapper {
    @Select("SELECT * FROM conversations WHERE buyer_id = 32 AND seller_id = #{stuId}")
    Conversations findAdminConversation(@Param("stuId") Integer stuId);

    @Insert("INSERT INTO conversations (goods_id, buyer_id, seller_id, last_msg, last_time, unread_count, status) " +
            "VALUES (#{goodsId}, #{buyerId}, #{sellerId}, #{lastMsg}, #{lastTime}, #{unreadCount}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "convId", keyColumn = "conv_id")
    void insert(Conversations conversation);

    @Update("UPDATE conversations SET last_msg = #{lastMsg}, last_time = #{lastTime}, " +
            "unread_count = #{unreadCount}, status = #{status} WHERE conv_id = #{convId}")
    void update(Conversations conversation);
}